import store from '@/store'
import Home from '@/views/Home/index.vue'

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
    meta: { title: '首页', fullPage: true },
  },
  {
    path: '/car-rental/:categoryId',
    name: 'car-rental',
    component: () => import('@/views/CarRental/index.vue'),
    meta: { title: '租车服务' },
  },
  {
    path: '/news',
    name: 'news',
    component: () => import('@/views/News/index.vue'),
    meta: { title: '最新资讯', fullPage: true },
  },
  {
    path: '/detail/:typeId',
    name: 'detail',
    component: () => import('@/views/Detail/index.vue'),
    meta: { title: '车辆详情' },
  },
  {
    path: '/news-detail/:newsId',
    name: 'news-detail',
    component: () => import('@/views/NewsDetail/index.vue'),
    meta: { title: '资讯详情' },
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/index.vue'),
    meta: { title: '登录', fullPage: true },
    beforeEnter: (to, from, next) => {
      if (!store.state.user.token) {
        next()
      } else {
        next('/home')
      }
    },
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/Register/index.vue'),
    meta: { title: '注册', fullPage: true },
  },
  {
    path: '/person-center',
    redirect: '/person-center/profile',
    name: 'person-center',
    component: () => import('@/views/PersonCenter/index.vue'),
    meta: { title: '个人中心' },
    children: [
      {
        path: 'profile',
        name: 'profile',
        component: () => import('@/views/PersonCenter/Profile/index.vue'),
        meta: { title: '个人资料' },
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/PersonCenter/Order/index.vue'),
        meta: { title: '我的订单' },
      },
    ],
  },
  {
    path: '/:path(.*)',
    name: 'NotFound',
    component: () => import('@/views/NotFound.vue'),
    meta: { title: '未找到此页面' },
  },
]

export default routes
